<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="hitokoto">:D 获取中...</div>
    <p id="from"></p>
    <!-- 以下写法，选取一种即可 -->

    <!-- 现代写法，推荐 -->
    <!-- 兼容低版本浏览器 (包括 IE)，可移除 -->

    <!--End-->
    <script>
        // var xhr = new XMLHttpRequest();
        //     var url = "https://api.xygeng.cn/one?" + Math.random();
        //     xhr.open("GET", url);

        //     xhr.onreadystatechange = function() {
        //         if (xhr.readyState == 4) {
        //             if (xhr.status == 200 || xhr.status == 304) {
        //                 var obj = xhr.responseXML;
        //                 // alert(xmlObj);
        //                 var data = Obj.data;
        //                 // alert(books.length);

        //                 div.innerHTML = data[content].innerHTML;
        //                 p.innerHTML = data[name].innerHTML;

        //             }
        //         }
        //     }
        var xhr = new XMLHttpRequest();
        xhr.open('get', 'https://v1.hitokoto.cn?' + Math.random());
        // xhr.open('get', 'https://api.xygeng.cn/one/get/');

        xhr.onreadystatechange = function() {
            if (xhr.readyState === 4) {
                var data = JSON.parse(xhr.responseText);
                var hitokoto = document.getElementById('hitokoto');
                var from = document.getElementById('from');
                hitokoto.innerText = data.hitokoto;
                from.innerText = data.from;
                // data.hitokoto;
            }
        }
        xhr.send();
    </script>

</body>

</html>